<template>
	<div>
		<!-- 到达提示窗 -->
		<uni-popup ref="arriveDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认到达" title="运单到达"
				@confirm="arriveDialogConfirm" :before-close="true" @close="closeDialog('arriveDialog')">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 300px;">
					<uni-forms ref="form" :modelValue="formData"  labelWidth="75px">
						<uni-forms-item label="运行线路">
							<view style="display: flex;align-items: center;height: 36px;">
								<text style="font-weight: bold;">{{formData.scheduleVo.lineVo.lineName}}:</text>
							</view>
							<!-- <view style="margin-top: 10px;">
								<text v-for="(item,index) in formData.scheduleVo.lineVo.stationList" :key="index">{{item.branchDept.deptName}}→</text>
							</view> -->
						</uni-forms-item>
						<uni-forms-item label="发车批次">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleNo}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="车型">
							<view style="display: flex;align-items: center;height: 36px;">
								{{carType_[formData.scheduleVo.carVo.carType]}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="车牌号">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.carVo.licensePlate}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="司机姓名">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.driverVo.driverName}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="联系电话">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.driverVo.phoneNumber}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="身份证号">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.driverVo.idCardNo}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="到达地址">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.deliveryDistrictName}}{{formData.deliveryAddress}}
							</view>
						</uni-forms-item>
					</uni-forms>
					<view style="height: 50px;"></view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 取消到达提示窗 -->
		<uni-popup ref="cancelArriveDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认" title="运单取消到达"
				@confirm="cancelArriveDialogConfirm">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<uni-forms ref="form" :modelValue="formData"  labelWidth="75px">
						<uni-forms-item label="运行线路">
							<view style="display: flex;align-items: center;height: 36px;">
								<text style="font-weight: bold;">{{formData.scheduleVo.lineVo.lineName}}:</text>
							</view>
							<!-- <view style="margin-top: 10px;">
								<text v-for="(item,index) in formData.scheduleVo.lineVo.stationList" :key="index">{{item.branchDept.deptName}}→</text>
							</view> -->
						</uni-forms-item>
						<uni-forms-item label="发车批次">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleNo}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="车型">
							<view style="display: flex;align-items: center;height: 36px;">
								{{carType_[formData.scheduleVo.carVo.carType]}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="车牌号">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.carVo.licensePlate}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="司机姓名">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.driverVo.driverName}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="联系电话">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.driverVo.phoneNumber}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="身份证号">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.scheduleVo.driverVo.idCardNo}}
							</view>
						</uni-forms-item>
						<uni-forms-item label="到达地址">
							<view style="display: flex;align-items: center;height: 36px;">
								{{formData.deliveryDistrictName}}{{formData.deliveryAddress}}
							</view>
						</uni-forms-item>
						<view style="display: flex;margin-top: 10px;color: #bf5f09;">
							<text>*确认取消当前运单{{formData.scheduleNo}}送达</text>
						</view>
					</uni-forms>
					<view style="height: 50px;"></view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script>
	import {
		waybillArrive,
		cancelWaybillArrive,
	} from '@/api/system/waybill.js'
	import {getDicts} from '@/api/system/dict.js'
	export default {
		props: {
			data: {
				type: Object,
				default: {}
			},
			carType_:{
				type: Array,
				default:[]
			},
		},
		data() {
			return {
				formData:{
					scheduleNo:''
				},
			}
		},
		watch: {
			data: {
			　　handler(newValue, oldValue) {
			　　　	this.formData=newValue
			　　},
			　　deep: true
			},
		},
		methods: {
			//关闭弹窗
			closeDialog(name){
				this.$refs[name].close()
			},
			//到达
			arrive(){
				this.$refs.arriveDialog.open()
			},
			//确认到达
			arriveDialogConfirm(){
				uni.showLoading({
					title: '确认到达...',
				})
				//发车完成
				waybillArrive(this.formData.scheduleNo).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						uni.showToast({
							title: '到达成功',
							icon: 'none'
						})
						this.$refs.arriveDialog.close()
						this.$parent.init()  //调用父组件的init函数，重新加载数据
						//this.$forceUpdate(); //重新加载数据
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}	
				})
			},
			//取消到达
			cancleArrive(){
				if(this.formData.unLoadId!='0')
				{
					uni.showToast({
						icon:'none',
						title:'请先取消卸车'
					})
					return
				}
				this.$refs.cancelArriveDialog.open()
			},
			//确认取消到达
			cancelArriveDialogConfirm(){
				uni.showLoading({
					title: '正在取消到达...',
				})
				cancelWaybillArrive(this.formData.scheduleNo).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						uni.showToast({
							title: '取消到达成功',
							icon: 'none'
						})
						
						this.$parent.init()  //调用父组件的init函数，重新加载数据
						//this.$forceUpdate(); //重新加载数据
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
		},
	}
</script>

<style scoped>

</style>